package com.example.myapplication.tack_22.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_22.RouteDetailsActivity;
import com.example.myapplication.tack_22.data.RouteData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.My> {
    private List<RouteData.DataDTO> list;
    private Context context;
    private View view;

    public RouteAdapter(List<RouteData.DataDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_22_route,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        if(!TextUtils.isEmpty(list.get(position).getLineName())){
            holder.lineName.setText(list.get(position).getLineName());
        }
        if(!TextUtils.isEmpty(list.get(position).getCurrentName())){
            holder.currentName.setText("当前站点："+list.get(position).getCurrentName());
        }
        if(!TextUtils.isEmpty(String.valueOf(list.get(position).getReachTime()))){
            holder.reachTime.setText("间隔时间："+list.get(position).getReachTime()+"分钟");
        }
        if(!TextUtils.isEmpty(list.get(position).getLineName())){
            holder.name.setText("下一站："+list.get(position).getPreStep().getName());
        }

        holder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String id = String.valueOf(list.get(position).getLineId());
                Intent intent = new Intent(context, RouteDetailsActivity.class);
                intent.putExtra(Common.COMMON,id);
                context.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView lineName;
        private TextView currentName;
        private TextView reachTime;
        private TextView name;

        private LinearLayout line;
        public My(@NonNull View itemView) {
            super(itemView);
            lineName = view.findViewById(R.id.lineName);
            currentName = view.findViewById(R.id.currentName);
            reachTime = view.findViewById(R.id.reachTime);
            name = view.findViewById(R.id.name);
            line = view.findViewById(R.id.line);
        }
    }
}
